package com.itheima.day06;

import java.util.*;

/**
 * 斗地主
 */
public class Demo07 {
    public static void main(String[] args) {

        //封装牌面
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};

        HashMap<Integer, String> pokerMap = new HashMap<>();

        int i = 0;
        pokerMap.put(i++, "大王");
        pokerMap.put(i++, "小王");

        //一个数字匹配4个花色
        for (String number : numbers) { //2
            for (String color : colors) { //{"♠", "♥", "♣", "♦"};
                pokerMap.put(i++, color + number);
            }
        }

       /* System.out.println(pokerMap);
        System.out.println(pokerMap.size());*/


        //取出编号
        Set<Integer> integers = pokerMap.keySet();
        //转成ArrayList
        ArrayList<Integer> inxlist = new ArrayList<>(integers);
        //2.洗牌
        Collections.shuffle(inxlist);

       // System.out.println(inxlist);

        //3.发牌
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        ArrayList<Integer> list3 = new ArrayList<>();
        ArrayList<Integer> diPai = new ArrayList<>();

        for (int i1 = 0; i1 < inxlist.size(); i1++) {
            Integer n = inxlist.get(i1);

            //判断是否为第三张
            if (n >= inxlist.size() - 3) {
                diPai.add(n);

            } else {
                if (i1 % 3 == 0) {
                    list1.add(n);
                } else if (i1 % 3 == 1) {
                    list2.add(n);
                } else if (i1 % 3 == 2) {
                    list3.add(n);
                }
            }
        }


        //排序
        Collections.sort(list1);
        Collections.sort(list2);
        Collections.sort(list3);
        Collections.sort(diPai);

        //4.看牌

        System.out.println("露丝" + mackPoker(list1, pokerMap));
        System.out.println("大咪咪" + mackPoker(list2, pokerMap));
        System.out.println("丽颖" + mackPoker(list3, pokerMap));
        System.out.println("底牌" + mackPoker(diPai, pokerMap));



    }

    //封装牌面
    public static String mackPoker(List<Integer> list, Map<Integer, String> map) {
        StringBuilder builder = new StringBuilder("[");
        for (int i = 0; i < list.size(); i++) {
            Integer indx = list.get(i);
            //用indx 做健取出值
            builder.append(map.get(indx));
            if (i < list.size() - 1) {
                builder.append(", ");
            } else {
                builder.append("]");
            }
        }

        return builder.toString();
    }

}